﻿/*Author：Lary Pan(itolmqj123@gmail.com)
 *Date  ：2016/6/11
 *Tips  ：选项卡中的子页面
 * */
using UnityEngine;
using System;

public class ViewPage
{
    private bool isFirst;
    protected int pageNum = 0;
	protected UIBase4Tab uiBase;
	protected Transform transform;

	public ViewPage(UIBase4Tab uiBase, Transform transform)
	{
		this.uiBase 	= uiBase;
		this.transform 	= transform;
        isFirst         = true;
	}

    public void SetActive(bool isActive)
	{
		transform.gameObject.SetActive(isActive);
		//if frist open this ViewPage, refresh it. Or do not; 
		if (isActive && isFirst)
		{
			isFirst = false;
			ReflashData();
		}
	}

	protected void SetBtnClick(GameObject obj, Action<GameObject> action)
	{
		uiBase.SetBtnClick(obj, action);
	}

	protected void SetItemClick(GameObject obj, int index, Action<int> action)
	{
		uiBase.SetItemClick(obj, pageNum * 1000 + index, action);
	}

	public virtual void InitUI() { }
	
	public virtual void InitData() { }
	
	/// <summary>
	/// 在数据变动需要刷新数据处理时调用
	/// </summary>
	public virtual void ReflashData() { }
}
